package b2.scene.fight.skills
{
	import b2.scene.fight.PlayState;
	import b2.scene.fight.TankSprite;
	
	import flash.geom.Rectangle;
	
	public class Aid extends AreaHarm
	{
		public function Aid(tankId:int, tankSide:int, level:int, skillArgs:Object)
		{
			super(tankId, tankSide, level, skillArgs);
		}
		
		protected override function hitOtherTank(ownerId:int, skillArea:SkillArea):void
		{
			for (var tankIdStr:String in getPlayState().tanks)
			{
				var otherTank:TankSprite = getPlayState().tanks[tankIdStr];
				if (otherTank != null && (tankId > 0 && otherTank.tankId > 0 || tankId < 0 && otherTank.tankId < 0))
				{
					if (skillArea.intersects(new Rectangle(otherTank.x + 2, otherTank.y + 2, PlayState.TILE_WIDTH - 4, PlayState.TILE_WIDTH - 4)))
					{
						AidTank(otherTank);
					}
				}
			}
		}
		
		private function AidTank(tankOnHit:TankSprite):void
		{
			if (skillArgs.effectIndex != null && skillArgs.effectIndex != 0)
			{
				getPlayState().addTankEffect(tankOnHit.tankId, tankId,skillArgs.effectIndex, skillArgs.effectDuration[0], 
					skillArgs.effectValue[0], skillArgs.effectValue2[0]);
			}
		}
	}
}